Módulo:Update
-- IMPORTS local pt = require('Module:Paramtest') local hc = pt.has_content local dt = pt.default_to -- exposed table local p = {} --[=[ -- -- HELPER TABLES AND FUNCTIONS -- --]=] -- replacement before calling encode -- as lua patterns local repl_before = { '%(' = , '%)' = '', '%!' = '', } -- replacements after calling encode -- as lua patterns local repl_after = { '%+' = '-', '%%2C' = '', '%%2F' = '', '%%3F' = '', '%%26%%2338%%3B' = '', '%%E2%%80%%93' = '', '%.' = '', '%%26quot%%3B' = '', '%%E2%%80%%99' = '', '%%26%%2339%%3B' = '', '%%C3%%B6' = 'o', '%%3A' = '', } -- converting month names to hex for sortkeys local hexmonthconv = { January = '1', February = '2', March = '3', April = '4', May = '5', June = '6', July = '7', August = '8', September = '9', October = 'A', November = 'B', December = 'C', } -- category mapping: {category name, type for use on date pages (eg 28 November) local category_info = { bts = {'Behind the Scenes updates', 'Behind the Scenes'}, community = {'Community updates', 'Comunidad'}, devblog = {'Developer Blogs', 'Developer Blog'}, event = {'Event updates', 'Actualización de evento'}, feedback = {'Feedback updates', 'Feedback'}, future = {'Future updates', 'Actualización futura'}, game = {'Game updates', 'Actualización del juego'}, shop = {'Shop updates', 'Actualización de la tienda'}, sof = {'Squeal of Fortune updates', 'Squeal of Fortune'}, sgs = {'Solomon\'s Store updates', 'Solomon\'s Store'}, support = {'Support updates', 'Soporte'}, technical = {'Technical updates', 'Actualización técnica'}, th = {'Treasure Hunter updates', 'Treasure Hunter'}, website = {'Website updates', 'Actualización del sitio web'}, '#default' = {'Falta categoría de actualización', ''}, } -- input mapping: accepted inputs -> keys for above table local cat_switch = { bts = 'bts', the scenes' = 'bts', comm = 'community', community = 'community', dev = 'devblog', blog = 'devblog', blog' = 'devblog', devblog = 'devblog', event = 'event', events = 'event', fb = 'feedback', feedback = 'feedback', yourfeedback = 'feedback', feedback' = 'feedback', future = 'future', game = 'game', shop = 'shop', ss = 'sgs', sgs = 'sgs', solomon = 'sgs', store' = 'sgs', sof = 'sof', squeal = 'sof', cs = 'support', customer = 'support', support' = 'support', support = 'support', tech = 'technical', technical = 'technical', th = 'th', treasure = 'th', hunter' = 'th', site = 'website', ws = 'website', website = 'website', '#default' = '#default' } -- given a supported 'category' code, return the name of the category function get_update_category(catarg) if hc(catarg) then catarg = string.gsub(string.lower(catarg), ' ?updates?', '') if cat_switchcatarg and category_info[cat_switchcatarg] then return category_info[cat_switchcatarg]1 else return category_info[cat_switch'#default']1 end else return category_info[cat_switch'#default']1 end end -- given d,m,y, return the relevant time-based categories (with sorting) function get_time_categories(day, month, year) local ret = {} local hexmonth, dayzero if not day or not month or not hexmonthconvmonth or not year then table.insert(ret, 'Category:Falta fecha de actualización') else dayzero = ((tonumber(day) < 10 and '0'..day) or day) hexmonth = hexmonthconvmonth -- Category:28 November updates, sorted by year (eg 2015) table.insert(ret, string.format('%s%s%s', day, month, year, hexmonth, dayzero)) -- Category:2015 updates, sorted by monthday, months converted to hex, eg B28 (28 November) table.insert(ret, string.format('%s%s', year, hexmonth, dayzero)) -- Category:Updates by date, sorted year month day table.insert(ret, string.format('%s%s%s', year, hexmonth, dayzero)) end return table.concat(ret) end -- lang for formatting date local lang = mw.getContentLanguage() -- current title local title = mw.title.getCurrentTitle() --[=[ -- -- TEMPLATES -- --]=] -- Template:Update function p.update(frame) local a = frame:getParent().args local div = mw.html.create('div') :addClass('official update') :done() local link if hc(a.link) then if a.link 'no' then link = 'official news post' else link = '.. a.link .. ' post de noticias oficial' end else link = string.lower(title.baseText) for i,v in pairs(repl_before) do link = string.gsub(link, i, v) end link = mw.uri.encode(link) for i,v in pairs(repl_after) do link = string.gsub(link, i, v) end link = '.. link .. ' official news post' end local date_link, day, month, year if hc(a.date) then local str day = lang:formatDate('j', a.date) month = lang:formatDate('F', a.date) year = lang:formatDate('Y', a.date) str = month str = str:gsub("^%l", string.upper) date_link = '' .. day .. ' de ' .. str .. ' de ' .. year .. '' else date_link = '(falta fecha)' end local date_link2 if hc(a.rev) then local str day = lang:formatDate('j', a.rev) month = lang:formatDate('F', a.rev) year = lang:formatDate('Y', a.rev) str = month str = str:gsub("^%l", string.upper) date_link2 = '' .. day .. ' de ' .. str .. ' de ' .. year .. '' date_link = date_link .. ', y revisado el ' .. date_link2, a.rev end if hc(a.author) then date_link = date_link .. ' por ' .. a.author end div:wikitext('Este ' .. link .. ' esta copiado textualmente desde ') :tag('span') :addClass('plainlinks') :wikitext('\'\'el sitio web de RuneScape\'\'') :done() :wikitext('. Los derechos de autor le pertenecen a Jagex.') :tag('br'):done() :wikitext('Fue agregado el ' .. date_link .. '.') :done() local cat = '' -- cats only in update namespace if title.namespace 100 then cat = '' .. title.text .. '' cat = cat .. get_time_categories(day, month, year) end local ret = frame:getParent():preprocess(' ') .. ' __NOEDITSECTION__' .. tostring(div) .. cat .. ' ' return ret end -- Template:Patch Notes function p.patchnotes(frame) local function qfclink(qfc) return 'http://services.runescape.com/m=forum/forums.ws?' .. string.gsub(qfc, '%-', ',') end local a = frame:getParent().args local cat = '' local div = mw.html.create('div') :addClass('official patchnote') :done() local link if hc(a.qfc) then if a.qfc 'no' then link = ' un hilo del foro' else link = '.. qfclink(a.qfc) .. ' este hilo del foro' end else link = '(Falta QFC)' cat = cat .. 'Category:Missing patch notes QFC' end local date_link local date_link2 local day, month, year = '', '', '' if hc(a.date) then local str day = lang:formatDate('j', a.date) month = lang:formatDate('F', a.date) year = lang:formatDate('Y', a.date) str = month str = str:gsub("^%l", string.upper) date_link = '' .. day .. ' de ' .. str .. ' de ' .. year .. '' else date_link = '(falta fecha)' end if hc(a.author) then date_link = date_link .. ' por ' .. a.author end if hc(a.rev) then local str local day1,month1,year1 = '',,'' day1 = lang:formatDate('j', a.rev) month1 = lang:formatDate('F', a.rev) year1 = lang:formatDate('Y', a.rev) str = month1 str = str:gsub("^%l", string.upper) date_link2= '' .. day1 .. ' de ' .. str .. ' de ' .. year1 .. '' date_link = date_link .. ', y revisadas el ' .. date_link2 end div:wikitext('Estas Patch Notes fueron copiadas textualmente desde ' .. link .. ' en los ') :tag('span') :addClass('plainlinks') :wikitext('\'\'foros de RuneScape\'\'') :done() :wikitext('. Los derechos de autor le pertenecen a Jagex.') :tag('br'):done() :wikitext('Estas Patch Notes fueron anunciadas el ' .. date_link .. '.') :done() cat = cat .. get_time_categories(day, month, year) -- not update namespace, remove cat if title.namespace ~= 100 then cat = '' end local str str = month str = str:gsub("^%l", string.upper) local ret = frame:getParent():preprocess(string.format(' ', day, str, year)) .. '__NOEDITSECTION__' .. tostring(div) .. cat .. ' __TOC__ ' return ret end -- Template:DevBlog function p.devblog(frame) local a = frame:getParent().args local blogtitle = dt(a.title, title.baseTitle) local cat = '' local div = mw.html.create('div') :addClass('official devblog') :done() local link if hc(a.link) then if a.link 'no' then link = "sitio web de RuneScape" else link = '[' .. a.link .. " sitio web de RuneScape]" end else link = title.baseText for i,v in pairs(repl_before) do link = string.gsub(link, i, v) end link = mw.uri.encode(link) for i,v in pairs(repl_after) do link = string.gsub(link, i, v) end link = '[http://services.runescape.com/m=rswiki/en/DevBlog:' .. link .. " sitio web de RuneScape]" end local date_link, day, month, year if hc(a.date) then day = lang:formatDate('j', a.date) month = lang:formatDate('F', a.date) year = lang:formatDate('Y', a.date) date_link = '' .. day .. ' ' .. month .. ' ' .. year .. '' else date_link = '(falta fecha)' end local authorstr = '' if hc(a.author) then authorstr = "" .. a.author .. "" else authorstr = '(falta autor)' cat = cat .. 'Category:Missing devblog author' end div:wikitext('Este Developer Blog esta copiado textualmente desde ') :tag('span') :addClass('plainlinks') :wikitext(link) :done() :wikitext('. Los derechos de autor le pertenecen a Jagex.') :tag('br'):done() :wikitext('Fue escrito por ' .. authorstr .. ' con fecha ' .. date_link .. '.') :done() local div2 = mw.html.create('div') :css({ 'font-size' = '150%', background = 'transparent none repeat scroll 0 0', 'border-bottom' = '1px solid #aaa', 'font-weight' = 'normal', 'margin-bottom' = '15px', 'padding-bottom' = '0.17em', 'padding-top' = '0.5em', 'text-align' = 'center', }) :wikitext(blogtitle) :done() -- cats only in update namespace if title.namespace 100 then cat = '' .. blogtitle .. '' cat = cat .. get_time_categories(day, month, year) else cat = '' end local ret = frame:getParent():preprocess(' ') .. ' __NOEDITSECTION__' .. tostring(div) .. cat .. tostring(div2) return ret end --[=[ -- -- CATEGORY FORMATTERS -- --]=] -- Category:28 November updates etc function p.date_cat(frame) local f = frame:getParent() local d if hc(f.args1) then d = f.args1 else -- assumes 2016 so that leap years work d = string.gsub(title.text, ' ?updates?', ) .. ' 2016' end local ret = 'This category contains updates posted on ' .. lang:formatDate('j F', d) .. ', sorted chronologically.' -- cats only in category namespace if title.namespace 14 then --updates by day, sorted by hexmonth,day: B28 (28 November) ret = ret .. '[by day|' .. hexmonthconv[lang:formatDate('F', d) .. lang:formatDate('d', d) .. ']]' --updates by month, sorted by spaceday ret = ret .. ' ' .. lang:formatDate('d', d) .. '' end return ret end function p.fecha(frame) local a = frame:getParent().args local date_link local date_link3 local day, month, year = '', '', '' if hc(a.date) then local str day = lang:formatDate('j', a.date) month = lang:formatDate('F', a.date) year = lang:formatDate('Y', a.date) str = month str = str:gsub("^%l", string.upper) date_link = ''.. day .. ' de ' .. month .. ' updates' date_link3 = ''..year.. ' updates' else date_link = '' end local ret = '' local ret2 = '' local a2 = '' local ret3= '' a2 = date_link cati, dia = "Category:", a2 ret2 = string.format("%s %s",cati,dia) ret3 = "Category:"..date_link3.."" return ret2,ret3 end -- Category:2015 updates etc function p.year_cat(frame) local f = frame:getParent() local d if hc(f.args1) then d = f.args1 else d = string.gsub(title.text, ' ?updates?', '') end local ret = 'This category contains updates posted in ' .. d .. ', sorted chronologically.' -- cats only in category namespace if title.namespace 14 then --updates by year, sorted by spaceyear ret = ret .. ' ' .. d .. '' end return ret end --[=[ -- -- DPL HANDLERS -- --]=] function p.datedpl(frame) local a = frame:getParent().args local year local cat local page = a'%TITLE%' if hc(a.year) then year = a.year else year = lang:formatDate('Y', a.date) end if hc(a.category) then -- if it has category, cat = category_info[cat_switch' ?updates?', '')]2 elseif hc(a.qfc) then -- if it has qfc, cat = 'Patch Notes' else -- missing both probably means cat = 'Antique update' end return string.format("'%s''' – %s: %s",year,cat,page,page) end --TODO --p.updatedpl --p.patchnotesdpl --etc return p